package 链表;

import common.ListNode;

import java.util.HashSet;
import java.util.Set;

/**
 * @author tmh
 * @date 2024/8/18 23:00
 * @description
 */
public class T141环形链表 {
    public boolean hasCycle(ListNode head) {
        //用set秒了
        Set<ListNode> set = new HashSet<>();
        while (head != null) {
            if (!set.add(head)){
                return true;
            }
            head=head.next;
        }
        return false;
    }
}
